/**
 * Created by Admin on 26.01.2015.
 */

var ColorProvider = (function ($) {
    return $.inherit({
        __constructor: function () {

        },

        getColor: function (datum, minZ, maxZ) {
            var c = Math.rescaleC(datum, minZ, maxZ, 0.1, 0.9);
            return [c, c, c, 0.0];
        }
    })
})(window["jQuery"]);

var ColorMap = (ColorProvider, function ($) {
    return $.inherit({
        colors: null,
        __constructor: function (colors) {
            this.colors = colors;
        },

        getColor: function (datum, min, max) {
            var colorIndex = Math.round(Math.rescaleC(datum, min, max, 0, this.colors.length - 1));
            var color = this.colors[colorIndex];
            return [color.r, color.g, color.b, 0.0];
        }
    }, {
        toGlFormat: function (c) {
            return Math.rescale(c, 0, 255, 0, 1);
        }
    })
})(window["jQuery"]);

ColorMap.Jet = (function ($) {

    var colors = [];
    var lc;
    for (lc = 128; lc < 256; lc++) {
        colors.push({
            r: 0.0,
            g: 0.0,
            b: ColorMap.toGlFormat(lc)
        })
    }

    for (lc = 0; lc < 256; lc++) {
        colors.push({
            r: 0.0,
            g: ColorMap.toGlFormat(lc),
            b: 1.0
        })
    }

    for (lc = 0; lc < 256; lc++) {
        colors.push({
            r: ColorMap.toGlFormat(lc),
            g: 1.0,
            b: ColorMap.toGlFormat(255 - lc)
        })
    }

    for (lc = 0; lc < 256; lc++) {
        colors.push({
            r: 1.0,
            g: ColorMap.toGlFormat(lc),
            b: 0.0
        })
    }

    for (lc = 255; lc > 128; lc--) {
        colors.push({
            r: ColorMap.toGlFormat(lc),
            g: 0.0,
            b: 0.0
        })
    }

    return new ColorMap(colors);
})(window["jQuery"]);